// Crowd.txt
// Script by Lazarus
// Makes random townsfolk for a city. Monster cap for a city is 85, but this makes use of the extra placed monster slots to get another 34.
// Default NPC set is the 6 townsfolk creatures and 2 merchant creatures. Other creatures can be added to the set using memory cells.
// Memory Cell 0 - X Radius to place monsters within. If 0, then defaults to 4.
// Memory Cell 1 - Y Radius to place monsters within. If 0, then defaults to 4.
// Memory Cell 2 - Number of creatures to place. Defaults to 4.
// Memory Cell 3-7 - Number of extra creature to include 

beginterrainscript;
variables;
short attitude,clear,crowd,toplace;
short xradius,yradius;
short xspot,yspot;
short numtoplace;
body;

beginstate init_state;
if(get_memory_cell(0) != 0)
	xradius = get_memory_cell(0);
else
	xradius = 4;

if(get_memory_cell(1) != 0)
	yradius = get_memory_cell(1);
else
	yradius = 4;
if(get_memory_cell(2) != 0)
	numtoplace = get_memory_cell(2);
else
	numtoplace = 4;
crowd = 0;
while(crowd < numtoplace){
	toplace = -1;
	while(toplace <= 0){
		toplace = get_ran(1,1000,1012);
		if(toplace == 1000)
			toplace = 1;
		if(toplace == 1001)
			toplace = 2;
		if(toplace == 1002)
			toplace = 74;
		if(toplace == 1003)
			toplace = 75;
		if(toplace == 1004)
			toplace = 76;
		if(toplace == 1005)
			toplace = 77;
		if(toplace == 1006)
			toplace = 78;
		if(toplace == 1007)
			toplace = 79;
		if(toplace == 1008)
			toplace = get_memory_cell(3);
		if(toplace == 1009)
			toplace = get_memory_cell(4);
		if(toplace == 1010)
			toplace = get_memory_cell(5);
		if(toplace == 1011)
			toplace = get_memory_cell(6);
		if(toplace == 1012)
			toplace = get_memory_cell(7);
	}
	clear = 0;
	while(clear == 0){
		xspot = get_ran(1,my_loc_x() - xradius,my_loc_x() + xradius);
		yspot =	get_ran(1,my_loc_y() - yradius,my_loc_y() + yradius);
		if(char_on_spot(xspot,yspot) == -1)
			clear = 1;
	}
	place_monster(xspot,yspot,toplace,0);
	crowd = crowd + 1;
	attitude = char_on_spot(xspot,yspot);
	set_attitude(attitude,3);
}
break;

beginstate start_state;
break;

beginstate search_state;
break;